/*
 * AParameterPlotter.java
 *
 * Created on November 7, 2008, 12:11 PM
 */

package curro;

import sequor.model.ParameterListModel;
import specto.Plottable;
import specto.euclidean2.Rectangle2D;
import specto.euclidean3.ParametricSurface3D;

/**
 *
 * @author  ae3263
 */
public class PAParametricSurfacePlotter extends javax.swing.JApplet {
    String[][] functions = { { "rx(u,v)=" , "(a+b*cos(u))*sin(v)", "u", "v" }, { "ry(u,v)=" , "(a+b*cos(u))*cos(v)", "u", "v" }, { "rz(u,v)=" , "c*sin(u)", "u", "v" } };
    Object[][] parameters = { { "a", 3 }, { "b", 1 }, { "c", 1 } };

    /** Initializes the applet AParameterPlotter */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
       
                    parameterListModel1=new ParameterListModel(parameters, settingsPanel1, functionPanel1);
                    ParametricSurface3D ps1 = new ParametricSurface3D(functionPanel1.getFunctionModel(0), functionPanel1.getFunctionModel(1), functionPanel1.getFunctionModel(2));
                    ps1.getDomainModel().xModel.setRangeProperties(0.0, 0.0, 2*Math.PI, Math.PI/6);
                    ps1.getDomainModel().yModel.setRangeProperties(0.0, 0.0, 2*Math.PI, Math.PI/6);
                    plot3D1.add(ps1);
                    
                    Plottable nv = ps1.getNormalVectors();
                    plot3D1.add(nv);
                    nv.setVisible(false);
                    ParametricSurface3D.SurfacePoint npt = ps1.getSurfacePoint();
                    plot3D1.add(npt);
                    
                    plot2D1.add(new Rectangle2D(npt.getConstraintModel()));
                    plot2D1.add(npt.getConstrainedPoint());
                    plot2D1.getVisometry().setDesiredBounds(-1.0,-1.0,7.0,7.0);
                    
                    plot3D1.getVisometry().setSceneSize(6.0);
                    plot3D1.getVisometry().setViewDist(6.0);
                    plot3D1.getVisometry().setEyeSep(0.2);
                    plot3D1.getVisometry().setDesiredBounds(-5.0, -5.0, 5.0, 5.0);
                    //plot2D1.add(new PlaneFunction2D(functionPanel1.getFunctionModel(0)));
                    //plot2D1.repaint();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        parameterListModel1 = new sequor.model.ParameterListModel();
        settingsPanel1 = new sequor.component.SettingsPanel();
        functionPanel1 = new sequor.component.FunctionPanel(functions);
        plot3D1 = new specto.euclidean3.Plot3D();
        plot2D1 = new specto.euclidean2.Plot2D();

        settingsPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
        settingsPanel1.setToolTipText("Right-click to remove parameter");
        settingsPanel1.setPreferredSize(new java.awt.Dimension(250, 332));
        getContentPane().add(settingsPanel1, java.awt.BorderLayout.LINE_END);
        getContentPane().add(functionPanel1, java.awt.BorderLayout.PAGE_END);

        plot3D1.setAnimatorVisible(false);
        plot3D1.setAxisStyle(0);
        plot3D1.setXyStyle(3);

        plot2D1.setAnimatorVisible(false);
        plot2D1.setAxisStyle(1);
        plot2D1.setMarkerBoxVisible(false);

        javax.swing.GroupLayout plot2D1Layout = new javax.swing.GroupLayout(plot2D1);
        plot2D1.setLayout(plot2D1Layout);
        plot2D1Layout.setHorizontalGroup(
            plot2D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 118, Short.MAX_VALUE)
        );
        plot2D1Layout.setVerticalGroup(
            plot2D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 102, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout plot3D1Layout = new javax.swing.GroupLayout(plot3D1);
        plot3D1.setLayout(plot3D1Layout);
        plot3D1Layout.setHorizontalGroup(
            plot3D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, plot3D1Layout.createSequentialGroup()
                .addContainerGap(360, Short.MAX_VALUE)
                .addComponent(plot2D1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        plot3D1Layout.setVerticalGroup(
            plot3D1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, plot3D1Layout.createSequentialGroup()
                .addContainerGap(204, Short.MAX_VALUE)
                .addComponent(plot2D1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(plot3D1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private sequor.component.FunctionPanel functionPanel1;
    private sequor.model.ParameterListModel parameterListModel1;
    private specto.euclidean2.Plot2D plot2D1;
    private specto.euclidean3.Plot3D plot3D1;
    private sequor.component.SettingsPanel settingsPanel1;
    // End of variables declaration//GEN-END:variables

}
